package com.xiaoyu.lanling.widget.picker.area;

import com.xiaoyu.base.app.AppContext;
import com.xiaoyu.lanling.R;

import java.util.ArrayList;
import java.util.List;

import in.srain.cube.request.JsonData;

public class PickerProvinceModel {

    public final String province;
    public final List<String> cityList;
    public final List<List<String>> countyList;

    public PickerProvinceModel(AreaBaseModel areaModel) {
        province = areaModel.getName();
        cityList = new ArrayList<>();
        countyList = new ArrayList<>();
        for (AreaBaseModel cityModel : areaModel.getChildList()) {
            cityList.add(cityModel.getName());

            List<String> countyNameList = new ArrayList<>();
            for (AreaBaseModel countyModel : cityModel.getChildList()) {
                countyNameList.add(countyModel.getName());
            }
            countyList.add(countyNameList);
        }
    }

    public PickerProvinceModel(JsonData jsonData) {
        List<JsonData> cityDataList = jsonData.optJson("cities").toList();

        province = jsonData.optString("province");
        cityList = new ArrayList<>(cityDataList.size());
        countyList = new ArrayList<>(cityDataList.size());

        for (JsonData cityRawData : cityDataList) {
            cityList.add(cityRawData.optString("city"));
            countyList.add(cityRawData.optJson("counties").asList());
        }
    }

    public PickerProvinceModel() {
        String unlimitedDoc = AppContext.getString(R.string.fate_preference_location_unlimited);
        province = unlimitedDoc;
        cityList = new ArrayList<>();
        countyList = new ArrayList<>();

        List<String> county = new ArrayList<>();
        county.add(unlimitedDoc);

        cityList.add(unlimitedDoc);
        countyList.add(county);
    }
}